package com.cloud.rocketmqtxconsumer.service.impl;

import com.cloud.rocketmqtxconsumer.entity.Pay;
import com.cloud.rocketmqtxconsumer.entity.TransactionInformation;
import com.cloud.rocketmqtxconsumer.mapper.PayMapper;
import com.cloud.rocketmqtxconsumer.mapper.TransactionInformationMapper;
import com.cloud.rocketmqtxconsumer.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@SuppressWarnings("all")
public class PayServiceImpl implements PayService {

    @Autowired
    private TransactionInformationMapper transactionInformationMapper;

    @Autowired
    private PayMapper payMapper;

    @Override
    public int selectTransactionInformationById(String transactionId) {
        return transactionInformationMapper.selectTransactionInformationById(transactionId);
    }

    @Override
    @Transactional
    public int insertPayInfo(Pay pay,String transactionId) {

        //正常的业务逻辑
        payMapper.insert(pay);
        //记录事务信息
        TransactionInformation information = TransactionInformation.builder().transactionId(transactionId).build();
        transactionInformationMapper.insertSelective(information);

        return 1;
    }

}
